package com.nobug;

import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

/**
 * @author 389561407@qq.com
 * @version 1.0
 * @since 2022-12-27
 */
public class MyRobot2 {


    private volatile static int flag = 0;

    private static int X = 1885;
    private static int Y = 458 ;

    public static void main(String[] args) throws AWTException {

        //1874  296

        //1871 435 钓鱼点中心

        // X 左 1871 + 20 右边 1941 = 1871 +70
        // Y 297 = 435 - 138

        // 横条的 Y 是 向上 100 435-100  rgb值为 -13750233 13959191


//        new Thread(() ->{
//            while (true){
//                sleep(500);
//                keyTime(KeyEvent.VK_SPACE,300);
//            }
//        }).start();

        //鼠标左键获取点击坐标的 rgb
        while (true){
            sleep(10);
            int rgb1 = getRGB(X+20,Y-137);
            int rgb2 = getRGB(X+20,Y-138);
            int rgb3 = getRGB(X+20,Y-139);
            if(rgb1==rgb2&&rgb1==rgb3){
                System.out.println(rgb1);
            }

        }


//        Robot robot = new Robot();
//        robot.mouseMove(10, 20);//移动鼠标到(10,20)点
//        robot.mousePress(InputEvent.BUTTON3_MASK);//按下右键
//        robot.mouseRelease(InputEvent.BUTTON3_MASK);//释放右键

//        robot.keyPress(KeyEvent.VK_1);
//        robot.keyPress(KeyEvent.VK_2);
//        robot.keyPress(KeyEvent.VK_3);
//        robot.keyPress(KeyEvent.VK_UP);
//        robot.keyPress(KeyEvent.VK_LEFT);
//        robot.keyPress(KeyEvent.VK_DOWN);
//        robot.keyPress(KeyEvent.VK_RIGHT);
//        System.out.println("机器123输入内容为123：111111111111111");
//        System.out.println("机器输112323入内容为：");
    }


    //获取鼠标停留位置坐标
    public static int[] getMouseXY(int s) {
        int rx = 0;
        int ry = 0;
        do{
            Point location = MouseInfo.getPointerInfo().getLocation();
            double x = location.getX();
            double y = location.getY();
//            System.out.println("X:"+x+" Y:"+y);
            if(rx != x || ry != y){
                rx =(int) x;
                ry =(int) y;
                num = 0;
//                System.out.println("请勿移动确定初始点");
            }else {
                num++;
//                System.out.println("保持"+s+"秒后确定初始点");
//                System.out.println("正在获取鼠标停留位置，请勿操作鼠标");

            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }while (num<(s<<1));

        return new int[]{rx,ry};
    }



    //获取自定点的rgb值
    public static int getRGB(int x, int y) {
        Color pixelColor = robot.getPixelColor(x, y);
        int rgb = pixelColor.getRGB();
        return rgb;

    }


    //获取自定点的rgb值
    public static int getRGB(int[] mouseXY) {
        Color pixelColor = robot.getPixelColor(mouseXY[0], mouseXY[1]);
        int rgb = pixelColor.getRGB();
        return rgb;
    }



    //按下一个按键 指定时间后释放
    public static void keyTime(int vkEnter,int time) {
        robot.keyPress(vkEnter);
        sleep(time);
        robot.keyRelease(vkEnter);
    }

    //按下一个按键 指定时间后释放
    public static void key(int vkEnter) {
        robot.keyPress(vkEnter);
        sleep(300);
        robot.keyRelease(vkEnter);
    }

    //组合键
    public static void key(int vkEnter, int vkEnter1) {
        robot.keyPress(vkEnter);
        sleep(300);
        robot.keyPress(vkEnter1);
        sleep(300);
        robot.keyRelease(vkEnter1);
        sleep(300);
        robot.keyRelease(vkEnter);
    }


    private static Robot robot;

    private static int num = 500;

    static {
        try {
            robot = new Robot();
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }



    public static void print(int[][] ints, int[][] ints1) {
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                System.out.print(ints[i][j]);
                if(ints1[i][j] == 0){
                    robot.keyPress(keyPress(ints[i][j]));
                    mySleep(800);
                }
                robot.keyPress(KeyEvent.VK_RIGHT);
                mySleep(100);
            }
            robot.keyPress(KeyEvent.VK_DOWN);
            mySleep(100);
            System.out.println();
        }

    }

    public static void print(int[][] ints) {
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                System.out.print(ints[i][j]);
                robot.keyPress(keyPress(ints[i][j]));
                mySleep(num);
                robot.keyPress(KeyEvent.VK_RIGHT);
                mySleep(num);
            }
            robot.keyPress(KeyEvent.VK_DOWN);
            mySleep(num);
            System.out.println();
        }
    }

    private static void mySleep(int i) {
        try {
            Thread.sleep(i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private static int keyPress(int i) {
        switch (i){
            case 1:
                return KeyEvent.VK_1;
            case 2:
                return KeyEvent.VK_2;
            case 3:
                return KeyEvent.VK_3;
            case 4:
                return KeyEvent.VK_4;
            case 5:
                return KeyEvent.VK_5;
            case 6:
                return KeyEvent.VK_6;
            case 7:
                return KeyEvent.VK_7;
            case 8:
                return KeyEvent.VK_8;
            case 9:
                return KeyEvent.VK_9;
        }
        return KeyEvent.VK_0;
    }


    //点击鼠标左键
    public static void lButton() {
        mySleep(300);
        robot.mousePress(InputEvent.BUTTON1_MASK);//按下左键
        mySleep(100);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);//释放左键
    }

    //点击鼠标右键
    public static void rButton() {
        mySleep(300);
        robot.mousePress(InputEvent.BUTTON3_MASK);//按下右键
        robot.mouseRelease(InputEvent.BUTTON3_MASK);//释放右键

    }


    public static void move(int[] mouseXY) {
        move(mouseXY[0],mouseXY[1]);
    }

    public static void move(int x,int y) {
        mySleep(100);
        robot.mouseMove(x, y);
    }

    public static void sleep(int i) {
        mySleep(i);
    }

}
